<?php
require_once 'Kanedo/Language/Exception.php';

class Kanedo_Language
{
	/**
	 * Default language
	 *
	 * @var string
	 */
	protected $_defaultLang = "de-de";
	/**
	 * Aktuelle Sprache
	 *
	 * @var string
	 */
	protected $_language;
	
	
	
	public function __construct()
	{
		$this->reloadLanguage();

	}
	
	protected function reloadLanguage($lang = null)
	{
		if ($lang === null)
		{
			if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
			{
				$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5);
				$this->_language = $lang;
			}else {
				$this->_language = $this->_defaultLang;
			}
		}else {
			$this->_language = $lang;
		}
		
	}
	
	public function changeDefaultLanguage($lang)
	{
		$lang = (string) $lang;
		$this->_defaultLang = $lang;
		$this->reloadLanguage();
	}
	
	public function getCurrentLanguage()
	{
		return $this->_language;
	}
	
	public function changeLanguage($lang)
	{
		$this->_language = $lang;
	}
	
}
?>